﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text.RegularExpressions;
using API;
using Google.Protobuf;
using libmp;
using mb;
using Xamarin.Essentials;

namespace hotfix
{
    public static class Entry
    {
        static mb.ILog logger = App.logger;
        static API.IStartOption startOption = App.StartOption;
        public static void Start()
        {
            Console.WriteLine("!! load hotfix: {0}, main:{1} !!", libmp.Util.BuildConfiguration, mb.AssemblyCreationDate.Value);
            ServiceLocator.Instance.Register<IGlobal, libmp.GlobalImpl>();
            ServiceLocator.Instance.Register<IPopManager, libmp.AlertImp>();

            if (startOption.GetBoolValue("showDeviceInfo"))
                showDeviceInfo();

            gRPC.Init();

            DataStore.Parse();
            DataStore.store.PullOnlineConfig();

            User.Init();
            User.me.Fetch();
            // return;

            ServiceLocator.Instance.Get<IGlobal>().OnDidLaunch();
        }

        static void showDeviceInfo()
        {

            var cacheDir = FileSystem.CacheDirectory;
            logger.Log("********DeviceInfo***********");
            logger.Log("cacheDir--------", cacheDir);
            logger.Log("appInfo", AppInfo.Name, AppInfo.PackageName, AppInfo.Version, AppInfo.VersionString);
            logger.Log("********DeviceInfo***********");
        }

    }

}